package com.changpay.zywy.ui.fragment.main

import android.content.Intent
import android.view.View
import com.changpay.zywy.R
import com.changpay.zywy.base.BaseMvpFragment
import com.changpay.zywy.constant.Constant
import com.changpay.zywy.ext.showToast
import com.changpay.zywy.mvp.contract.CountContract
import com.changpay.zywy.mvp.presenter.CountPresenter
import com.changpay.zywy.ui.activity.count.*
import com.changpay.zywy.ui.activity.mine.RenZhenActivity
import com.changpay.zywy.utils.Preference
import kotlinx.android.synthetic.main.fragment_count.*

class CountFragment : BaseMvpFragment<CountContract.View, CountContract.Presenter>(), CountContract.View {


    /**
     * local password
     */
    private var approve: Int by Preference(Constant.IS_APPROVE, 0)

    private val onClickListener = View.OnClickListener { view ->
        if (approve == 0) {
            showToast("请先实名认证")
            startActivity(RenZhenActivity::class.java)
            return@OnClickListener
        }
        val type = when (view.id) {
            R.id.total_one -> 1
            R.id.total_two -> 2
            R.id.total_three -> 3
            else -> 1
        }
        Intent(context, CountTotalActivity::class.java).run {
            putExtra("type", type)
            startActivity(this)
        }
    }

    private val onClickListenerTwo = View.OnClickListener { view ->
        if (approve == 0) {
            showToast("请先实名认证")
            startActivity(RenZhenActivity::class.java)
            return@OnClickListener
        }
        val type = when (view.id) {
            R.id.trend_one -> 1
            R.id.trend_two -> 2
            R.id.trend_three -> 3
            else -> 1
        }
        Intent(context, CountTrendActivity::class.java).run {
            putExtra("type", type)
            startActivity(this)
        }
    }

    private val onClickListenerThree = View.OnClickListener { view ->
        if (approve == 0) {
            showToast("请先实名认证")
            startActivity(RenZhenActivity::class.java)
            return@OnClickListener
        }
        when (view.id) {
            R.id.ll_shop_trand -> {
                startActivity(CountShopTrandActivity::class.java)
            }
            R.id.ll_member_trand -> {
                startActivity(CountQuDaoTrandActivity::class.java)
            }
            R.id.ll_month_trand -> {
                startActivity(CountTrandMonthActivity::class.java)
            }

            R.id.ll_action_total -> {
                startActivity(CountActionTotalActivity::class.java)
            }
            R.id.ll_month_acton -> {
                startActivity(CountActionMonthActivity::class.java)
            }
            R.id.ll_add_shop -> {
                Intent(context, CountAddShopActivity::class.java).run {
                    putExtra("type", "shop")
                    startActivity(this)
                }
            }
            R.id.ll_add_member -> {
                Intent(context, CountAddShopActivity::class.java).run {
                    putExtra("type", "member")
                    startActivity(this)
                }
            }
        }

    }

    companion object {
        fun getInstance(): CountFragment = CountFragment()
    }

    override fun createPresenter(): CountContract.Presenter = CountPresenter()

    override fun attachLayoutRes(): Int = R.layout.fragment_count

    override fun lazyLoad() {
    }

    override fun initView(view: View) {
        super.initView(view)
        total_one.setOnClickListener(onClickListener)
        total_two.setOnClickListener(onClickListener)
        total_three.setOnClickListener(onClickListener)
        trend_one.setOnClickListener(onClickListenerTwo)
        trend_two.setOnClickListener(onClickListenerTwo)
        trend_three.setOnClickListener(onClickListenerTwo)
        ll_shop_trand.setOnClickListener(onClickListenerThree)
        ll_member_trand.setOnClickListener(onClickListenerThree)
        ll_month_trand.setOnClickListener(onClickListenerThree)
        ll_action_total.setOnClickListener(onClickListenerThree)
        ll_month_acton.setOnClickListener(onClickListenerThree)
        ll_add_shop.setOnClickListener(onClickListenerThree)
        ll_add_member.setOnClickListener(onClickListenerThree)
    }
}